package com.nuc.bigdata.controller;

import com.nuc.bigdata.orm.entity.CommodityClicks;
import com.nuc.bigdata.orm.feign.CommodityDetailFeign;
import com.nuc.bigdata.orm.feign.CommodityFeign;
import com.nuc.bigdata.service.GoodsDetailsService;
import com.nuc.bigdata.service.HomeInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 商品服务controller
 * @author JackLuo
 * @date 2019/11/28
 */
@RestController
@RequestMapping("/oa-commodity")
public class CommodityController {

    private final HomeInfoService homeInfoService;
    private final GoodsDetailsService detailsService;

    @Autowired
    CommodityController(HomeInfoService homeInfoService,
                        GoodsDetailsService detailsService) {
        this.homeInfoService = homeInfoService;
        this.detailsService = detailsService;
    }

    /**
     * 获取所有的商品feign
     * @param pageSize 查询页码
     * @return  包含商品feign的ArrayList
     */
    @GetMapping("/goods")
    public ArrayList<CommodityFeign> listAllCommodity(@RequestParam("pageSize")Long pageSize) {
        return homeInfoService.listAll(pageSize);
    }

    /**
     * 根据商品唯一标识获取商品详情feign
     * @param commodityId 商品唯一标识
     * @return 提供给front服务的商品详情feign
     */
    @GetMapping("/goods/{commodityId}")
    public CommodityDetailFeign queryDetailByCommodityId(@PathVariable("commodityId")String commodityId) {
        return detailsService.queryByCommodityId(commodityId);
    }

    /**
     * 根据商品唯一标识获取商品大概feign
     * @param commodityId 商品唯一标识
     * @return 提供给front服务的商品大概feign
     */
    @GetMapping("/goods/{commodityId}/rough")
    public CommodityFeign queryCommodityFeignById(@PathVariable("commodityId")String commodityId) {
        return homeInfoService.queryByCommodityId(commodityId);
    }
}
